#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

int m[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

/* generates the all arrangement
   call it with start and set number  */
void generate(int i, int n) {
    if (i == n) {
      // cout an arrangement
      for (int j = 1; j <= n; ++j) {
        cout<<m[j]<<' ';
      }
      cout<<endl;
    }
    for (int j = i; j <= n; ++j) {
      // swap j and i
      int tmp = m[j]; m[j] = m[i]; m[i] = tmp;
      generate(i+1, n);
      // swap back
      tmp = m[j]; m[j] = m[i]; m[i] = tmp;
    }
}
/* pick n elements from m1-set
   call it with empty vector and index 1
 */
void combination(vector<int> cur, int index, int n, int m1) {
  if (cur.size() == n) {
    for (int i = 0; i < cur.size(); ++i)
      cout<<cur[i]<<' ';
    cout<<endl;
    return;
  }
  for (int i = index; i <= m1 - (n - cur.size()) + 1; ++i) {
    vector<int> tmp = cur;
    tmp.push_back(i);
    combination(tmp, i+1, n, m1);
  }
}

int main(int argc, char*argv[]) {
  if (argc < 2) {
    generate(1, 9);
  } else {
    if (atoi(argv[1]) <= 9) {
      generate(1, atoi(argv[1]));
    } else {
      // error
      cout<<"This edition of the generator only output the arrangement of the number in 1 to 9."<<endl;
      cout<<"Please give a small number between 1 to 9, included the 1 and 9."<<endl;
    }
  }
  vector<int> v;
  v.clear();
  combination(v, 1, 2, 5);
}
